package com.ruoyi.web.controller.carbon;

import com.ruoyi.carbon.domain.vo.PandianVo;
import com.ruoyi.carbon.service.PandianInfoService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Anonymous
@RequestMapping("/carbon/pandianInfo")
public class PandianInfoController extends BaseController {

    @Autowired
    private PandianInfoService pandianInfoService;

    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PandianVo pandianVo) {
        startPage();
        List<PandianVo> list = pandianInfoService.list(pandianVo);
        return getDataTable(list);
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        int num = pandianInfoService.remove(ids);
        return toAjax(num);
    }

    @PostMapping
    public AjaxResult add(@Validated @RequestBody PandianVo pandianVo) {
        return toAjax(pandianInfoService.saveOrUpdate(pandianVo));
    }

    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PandianVo pandianVo) {
        return toAjax(pandianInfoService.saveOrUpdate(pandianVo));
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        return success(pandianInfoService.getById(id));
    }
}
